package com.transaction.service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;

@Component("productDao")
public class ProductDaoImpl extends HibernateDaoSupport implements ProductDao {

	private SessionFactory mySessionFactory;

	@Resource
	@Qualifier("sessionFactory")
	public void setMySessionFactory(SessionFactory mySessionFactory) {
		this.mySessionFactory = mySessionFactory;
	}
	
	@PostConstruct
	public void setSuperSessionFactory() {
		super.setSessionFactory(mySessionFactory);
	}
	@Override
	public Integer add(ProductDto productDto) {
		Product product = new Product();
		product.setName(productDto.getName());
		return (Integer)this.getHibernateTemplate().save(product);

	}
	@Override
	public void update(ProductDto productDto) {
		Product product = new Product();
		product.setId(productDto.getId());
		product.setName(productDto.getName());
		this.getHibernateTemplate().merge(product);
	}

}
